package com.six.firstpage.controller.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.six.core.entity.Banner;
import com.six.core.vo.Result;
import com.six.firstpage.service.BannerService;
import com.six.firstpage.vo.SearchVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author:zzh
 * @create: 2023-02-28 11:30
 * @Description:
 */
@Api(value = "/firstpage/api/banner", tags = {"轮播图前端Api"})
@RestController
@RequestMapping("/firstpage/api/banner")
public class ApiBannerController {
    @Autowired
    private BannerService bannerService;

    @ApiOperation(value = "", notes = "", httpMethod = "GET")
    @GetMapping("/getAllBanner")
    public Result getAllBanner(){
        List<Banner> allBanner = bannerService.getAllBanner();
        return new Result(2000,"查询前台轮播图成功",allBanner);
    }


    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "title", value = "", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "status", value = "", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "current", value = "", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "", required = false)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "POST")
    @PostMapping("getBannerByTitle/{current}/{pageSize}")
    public Result getBannerByTitle(@RequestBody SearchVo searchVo, @PathVariable Integer current, @PathVariable   Integer pageSize){
        Page<Banner> bannerByTitle = bannerService.getBannerByTitle(searchVo.getTitle(), searchVo.getStatus(), current, pageSize);
        return new Result(2000,"查询轮播图成功",bannerByTitle);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Banner", name = "banner", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "POST")
    @PostMapping("addBanner")
    public Result addBanner(@RequestBody Banner banner){
        Integer integer = bannerService.addBanner(banner);
        if (integer>0){
            return new Result(2000,"添加轮播图成功");
        }
        return new Result(5000,"添加轮播图失败");
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Banner", name = "banner", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "PUT")
    @PutMapping("updateBanner")
    public Result updateBanner(@RequestBody Banner banner){
        Integer integer = bannerService.updateBanner(banner);        if (integer>0){
            return new Result(2000,"添加轮播图成功");
        }
        return new Result(5000,"添加轮播图失败");
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "id", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "GET")
    @GetMapping("/delBanner/{id}")
    public Result delBanner(@PathVariable Integer id){
        Integer integer = bannerService.delBanner(id);
        if (integer>0){
            return new Result(2000,"添加轮播图成功");
        }
        return new Result(5000,"添加轮播图失败");
    }
}
